package cn.bugstack.domain.activity.service.diccount.impl;

import cn.bugstack.domain.activity.model.valobj.GroupBuyActivityDiscountVO;
import cn.bugstack.domain.activity.service.diccount.AbstractDiscountCalculateService;
import cn.bugstack.types.common.Constants;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service("MJ")
public class MJCalculateService extends AbstractDiscountCalculateService {
    @Override
    protected BigDecimal doCalculate(BigDecimal originalPrice, GroupBuyActivityDiscountVO.GroupBuyDiscount groupBuyDiscount) {
        String marketExpr = groupBuyDiscount.getMarketExpr();
        String[] split = marketExpr.split(Constants.SPLIT);
        BigDecimal limitDecimal = new BigDecimal(split[0]);
        BigDecimal subDecimal = new BigDecimal(split[1]);

        return (originalPrice.compareTo(limitDecimal)) >= 0 ? originalPrice.subtract(subDecimal): originalPrice;
    }
}
